#include "peopletreenode.h"

PeopleTreeNode::PeopleTreeNode(const QString &type, const QString &name, int id) :
    m_type(type), m_name(name), m_id(id), m_parent(0)
{
}

PeopleTreeNode::~PeopleTreeNode()
{
    qDeleteAll(m_childrens);
}

QString PeopleTreeNode::name() const
{
    return m_name;
}

int PeopleTreeNode::id() const
{
    return m_id;
}

PeopleTreeNode *PeopleTreeNode::parent() const
{
    return m_parent;
}

void PeopleTreeNode::setParent(PeopleTreeNode *parent)
{
    m_parent = parent;
}

PeopleTreeNode *PeopleTreeNode::child(int row) const
{
    if (row < 0 || row >= m_childrens.size())
        return 0;
    return m_childrens.at(row);
}

int PeopleTreeNode::childIndex(PeopleTreeNode *child) const
{
    return m_childrens.indexOf(child);
}

int PeopleTreeNode::childCount() const
{
    return m_childrens.count();
}

void PeopleTreeNode::appendChild(PeopleTreeNode *child)
{
    m_childrens.append(child);
    child->setParent(this);
}

QIcon PeopleTreeNode::icon() const
{
    return QIcon("images/" + m_type + ".png");
}

QString PeopleTreeNode::type() const
{
    return m_type;
}
